﻿@model Controller2.Models.Entrada
@{
    Layout = null;
}
<!DOCTYPE html>
<html class="no-js">
<head>
    <title>Cadastro</title>
	@(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.vista.css").Combined(true).Compress(true)))
	@if (!Request.IsAjaxRequest())
    {
        <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
        <link href="../../Content/themes/controller/controller.css" rel="stylesheet" type="text/css" />
        @(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.vista.css").Combined(true).Compress(true)))  
        <script src="@Url.Content("~/Scripts/jquery.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>    
        <script src="@Url.Content("~/Scripts/jquery.maskedinput-1.3.min.js")" type="text/javascript"></script>
             <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    }	
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/controller.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/numbers.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.maskedinput-1.3.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
	<style type="text/css">
		fieldset
		{
			width: 570px;
		}
		.display-label, .editor-label
		{
			width: 130px;
            text-align: right;
            padding-right: 5px;
		}
        #IdMidia
        {
            width: 400px;
        }
        textarea#Descricao
        {
            width: 400px;
        }
	</style>
    @if (false)
    {
        <script src="../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../Scripts/jquery-ui.js" type="text/javascript"></script>
        <script src="../../Scripts/controller.js" type="text/javascript"></script>
    }
</head>
<body id="frame">
    <div id="formHide">
    	@using (Html.BeginForm("Salvar", "Entrada", FormMethod.Post)) {
        	@Html.ValidationSummary(true)
    	    <fieldset>
    	        <legend>Entrada</legend>
        		@Html.HiddenFor(model => model.IdEntrada) 
    		    <div class="editor-label">
    		        @Html.LabelFor(model => model.DataPrevista, "Data Prevista: ") 
    		    </div>
    		    <div class="editor-field">
    		        @Html.EditorFor(model => model.DataPrevista)
    				@Html.ValidationMessageFor(model => model.DataPrevista) 
    			</div>
    		    <div class="editor-label">
    		        @Html.LabelFor(model => model.DataRecebimento, "Data Recebimento: ") 
    		    </div>
    		    <div class="editor-field">
    		        @Html.EditorFor(model => model.DataRecebimento)
    				@Html.ValidationMessageFor(model => model.DataRecebimento) 
    			</div>
    			<div class="editor-label">
    		        @Html.LabelFor(model => model.ValorPrevisto, "Valor Previsto: ") 
    		    </div>
    		    <div class="editor-field">
    				@Html.TextBoxFor(model => model.ValorPrevisto, new { tipo = "decimal", tamanho = "2", @class = "obrigatorio valor", maxlength = "16" }) 
    				@Html.ValidationMessageFor(model => model.ValorPrevisto) 
    			</div>
    			<div class="editor-label">
    		        @Html.LabelFor(model => model.ValorRecebimento, "Valor Recebimento: ") 
    		    </div>
    		    <div class="editor-field">
    				@Html.TextBoxFor(model => model.ValorRecebimento, new { tipo = "decimal", tamanho = "2", @class = "valor", maxlength = "16" }) 
    				@Html.ValidationMessageFor(model => model.ValorRecebimento) 
    			</div>
    			<div class="editor-label">
    		        @Html.LabelFor(model => model.IdMidia, "Mídia") 
    		    </div>
    		    <div class="editor-field">
    				@Html.DropDownListFor(model => model.IdMidia, (IEnumerable<SelectListItem>)ViewBag.Midia, String.Empty, new { @class = "obrigatorio "})
    				@Html.ValidationMessageFor(model => model.IdMidia) 
    			</div>
    			<div class="editor-label">
    		        @Html.LabelFor(model => model.Descricao, "Descrição: ") 
    		    </div>
    		    <div class="editor-field">
    				@Html.TextAreaFor(model => model.Descricao, new { maxlength = "500", @class = "obrigatorio textArea" }) 
    				@Html.ValidationMessageFor(model => model.Descricao) 
    			</div>
    		</fieldset>        
            <div id="botoesForm">
                <input type="submit" id="Gravar" value="Gravar" />
                <input type="button" id="Fechar" value="Cancelar" />
            </div>
        }
    	</div>
        <div id="alertaErro" style="display: none">
        </div>
        <script type="text/javascript"> 					 
    		// custom validate para campos numéricos
    		$.validator.methods.qtdeMinima = function (value, element, param) { return $(element).valueFloat() > 0 ? true : false; };
    		$.validator.methods.dataValidate = function (value, element, param) { return validaData(element); };
            $(function () {
                $('.valor').each(function () {
    			    $(this).rules("remove");
    			    if ($(this).attr("id") == "ValorPrevisto") {
    			        $(this).rules("add", {
    			            qtdeMinima: true,
    			            messages: {
    			                qtdeMinima: "*"
    			            }
    			        });
    			    }
    			});
    			$('.datepicker').each(function () {
    			    $(this).rules("add", {
    			        dataValidate: true,
    			        messages: {
    			            dataValidate: "*"
    			        }
    			    });
    			});
    			$('.datepicker').mask("99/99/9999");
                textarea_maxlength("Descricao", "500");
                $('#formHide').fadeIn('slow');    		
                hideLoading();					
    		    $('#ValorPrevisto').focus();
            });

            $('form').submit(function (e) {
                e.preventDefault();
                if ($('form').valid()) {
                    if ($('#ValorRecebimento').val() == "0,00") {
                        $('#ValorRecebimento').val('');
                    }
                    $.post('@Url.Action("Salvar", "Entrada")', $('form').serialize(), function (data) {
                        if (data.salvo) {
                            closeWindow();
                        } else {
                            alertError(data.error);
                        }
                        $('#gravar').attr('disabled', false);
                    });
                }
            });
    	    $('#Fechar').click(function () { closeWindow(); });
        </script>
</body>
</html>

